package com.dlc.commonlibrary.adapter;

import android.view.View;
import android.widget.LinearLayout;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dlc.commonlibrary.R;
import com.dlc.commonlibrary.dialog.FindInfoData;
import java.util.ArrayList;

/**
 * Created by John on 2017/7/24.
 */

public class FindInfoAdapter extends BaseQuickAdapter<FindInfoData,BaseViewHolder> {
    private int layoutPosition = -1;
    private OnRecyclerViewItemClickListener mOnItemClickListener;
    public FindInfoAdapter() {
        super(R.layout.item_find_info, new ArrayList<FindInfoData>());
    }

    @Override
    protected void convert(final BaseViewHolder helper, FindInfoData item) {
        int position = helper.getLayoutPosition();
        helper.setText(R.id.name, item.goods_name);
        helper.setText(R.id.epc, item.epc_number);
        LinearLayout linearLayout = helper.getView(R.id.linear);
        linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //获取当前点击的位置
                layoutPosition = helper.getLayoutPosition();
                notifyDataSetChanged();
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.onItemClick(helper.itemView, "", layoutPosition);
                }
            }
        });

        //更改状态
        if(position == layoutPosition){
            linearLayout.setBackgroundResource(R.drawable.yellow_text_pressed);
        }else{
            linearLayout.setBackgroundResource(R.drawable.yellow_text_normal);
        }
    }
    public  interface OnRecyclerViewItemClickListener {
        void onItemClick(View view, String data, int position);
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
}
